/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TOrderReturn;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TOrderReturnDao;
import com.ruipengkj.service.TOrderReturnService;
/**
 * 说明：
 * 销售退货Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class TOrderReturnServiceImpl implements TOrderReturnService{
	@Resource
	private TOrderReturnDao TOrderReturnDao;//DAO层
	
	//查询所有
	@Override
	public List<TOrderReturn> findService(TOrderReturn entity) throws Exception {
		String hql = "select o from TOrderReturn o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TOrderReturnDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

	//根据ID翻页查询
	@Override
	public PageModel<TOrderReturn> getScrollService(int firstResult,
			int maxResult, TOrderReturn entity) throws Exception {
		String hql = "select o from TOrderReturn o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getReturnID()!=null&&!entity.getReturnID().equals("")){
				whereHQL.append("o.returnID").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getReturnID()+"%");
			}
			if(entity.getTUser()!=null&&entity.getTUser().getRealName() != null &&!entity.getTUser().getRealName().equals("")){
				whereHQL.append("o.TUser.realName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getTUser().getRealName()+"%");
			}
			//按时间查询
			if(entity.getStartTime()!=null&&!entity.getStartTime().equals("")){
				whereHQL.append("o.happenTime>=?").append(BaseQuery.AND);
				param.add(entity.getStartTime());
			}
			if(entity.getEndTime()!=null&&!entity.getEndTime().equals("")){
				whereHQL.append("o.happenTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TOrderReturnDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}
	//修改
	@Override
	public void modifyService(TOrderReturn entity) throws Exception {
		TOrderReturnDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(TOrderReturn entity) throws Exception {
		TOrderReturnDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TOrderReturnDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TOrderReturn getByIdService(String id) throws Exception {
		return TOrderReturnDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TOrderReturn entity) throws Exception {
		TOrderReturnDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TOrderReturn entity) throws Exception {
		return TOrderReturnDao.saveRetDao(entity);
	}

	public TOrderReturnDao getTOrderReturnDao() {
		return TOrderReturnDao;
	}

	public void setTOrderReturnDao(TOrderReturnDao TOrderReturnDao) {
		this.TOrderReturnDao = TOrderReturnDao;
	}	
	
	@Override
	public int executeSQL(String sql) {
		return TOrderReturnDao.executeSQL(sql);
	}

	@Override
	public List<Object[]> querySQL(String sql) {
		return TOrderReturnDao.querySQL(sql);
	}
}

